<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html>
<head>
  <title>make_request (GData::HTTP::DefaultService)</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  <link rel="stylesheet" href="../../../.././rdoc-style.css" type="text/css" media="screen" />
</head>
<body class="standalone-code">
  <pre><span class="ruby-comment cmt"># File lib/gdata/http/default_service.rb, line 29</span>
      <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">make_request</span>(<span class="ruby-identifier">request</span>)
        <span class="ruby-identifier">url</span> = <span class="ruby-constant">URI</span>.<span class="ruby-identifier">parse</span>(<span class="ruby-identifier">request</span>.<span class="ruby-identifier">url</span>)
        <span class="ruby-identifier">http</span> = <span class="ruby-constant">Net</span><span class="ruby-operator">::</span><span class="ruby-constant">HTTP</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">url</span>.<span class="ruby-identifier">host</span>, <span class="ruby-identifier">url</span>.<span class="ruby-identifier">port</span>)
        <span class="ruby-identifier">http</span>.<span class="ruby-identifier">use_ssl</span> = (<span class="ruby-identifier">url</span>.<span class="ruby-identifier">scheme</span> <span class="ruby-operator">==</span> <span class="ruby-value str">'https'</span>)
        <span class="ruby-identifier">http</span>.<span class="ruby-identifier">verify_mode</span> = <span class="ruby-constant">OpenSSL</span><span class="ruby-operator">::</span><span class="ruby-constant">SSL</span><span class="ruby-operator">::</span><span class="ruby-constant">VERIFY_NONE</span>
        
        <span class="ruby-keyword kw">case</span> <span class="ruby-identifier">request</span>.<span class="ruby-identifier">method</span>
        <span class="ruby-keyword kw">when</span> <span class="ruby-identifier">:get</span>
          <span class="ruby-identifier">req</span> = <span class="ruby-constant">Net</span><span class="ruby-operator">::</span><span class="ruby-constant">HTTP</span><span class="ruby-operator">::</span><span class="ruby-constant">Get</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">url</span>.<span class="ruby-identifier">request_uri</span>)
        <span class="ruby-keyword kw">when</span> <span class="ruby-identifier">:put</span>
          <span class="ruby-identifier">req</span> = <span class="ruby-constant">Net</span><span class="ruby-operator">::</span><span class="ruby-constant">HTTP</span><span class="ruby-operator">::</span><span class="ruby-constant">Put</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">url</span>.<span class="ruby-identifier">request_uri</span>)
        <span class="ruby-keyword kw">when</span> <span class="ruby-identifier">:post</span>
          <span class="ruby-identifier">req</span> = <span class="ruby-constant">Net</span><span class="ruby-operator">::</span><span class="ruby-constant">HTTP</span><span class="ruby-operator">::</span><span class="ruby-constant">Post</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">url</span>.<span class="ruby-identifier">request_uri</span>)
        <span class="ruby-keyword kw">when</span> <span class="ruby-identifier">:delete</span>
          <span class="ruby-identifier">req</span> = <span class="ruby-constant">Net</span><span class="ruby-operator">::</span><span class="ruby-constant">HTTP</span><span class="ruby-operator">::</span><span class="ruby-constant">Delete</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">url</span>.<span class="ruby-identifier">request_uri</span>)
        <span class="ruby-keyword kw">else</span>
          <span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-value str">&quot;Unsupported HTTP method specified.&quot;</span>
        <span class="ruby-keyword kw">end</span>
        
        <span class="ruby-keyword kw">case</span> <span class="ruby-identifier">request</span>.<span class="ruby-identifier">body</span>
        <span class="ruby-keyword kw">when</span> <span class="ruby-constant">String</span>
          <span class="ruby-identifier">req</span>.<span class="ruby-identifier">body</span> = <span class="ruby-identifier">request</span>.<span class="ruby-identifier">body</span>
        <span class="ruby-keyword kw">when</span> <span class="ruby-constant">Hash</span>
          <span class="ruby-identifier">req</span>.<span class="ruby-identifier">set_form_data</span>(<span class="ruby-identifier">request</span>.<span class="ruby-identifier">body</span>)
        <span class="ruby-keyword kw">when</span> <span class="ruby-constant">File</span>
          <span class="ruby-identifier">req</span>.<span class="ruby-identifier">body_stream</span> = <span class="ruby-identifier">request</span>.<span class="ruby-identifier">body</span>
          <span class="ruby-identifier">request</span>.<span class="ruby-identifier">chunked</span> = <span class="ruby-keyword kw">true</span>
        <span class="ruby-keyword kw">when</span> <span class="ruby-constant">GData</span><span class="ruby-operator">::</span><span class="ruby-constant">HTTP</span><span class="ruby-operator">::</span><span class="ruby-constant">MimeBody</span>
          <span class="ruby-identifier">req</span>.<span class="ruby-identifier">body_stream</span> = <span class="ruby-identifier">request</span>.<span class="ruby-identifier">body</span>
          <span class="ruby-identifier">request</span>.<span class="ruby-identifier">chunked</span> = <span class="ruby-keyword kw">true</span>
        <span class="ruby-keyword kw">else</span>
          <span class="ruby-identifier">req</span>.<span class="ruby-identifier">body</span> = <span class="ruby-identifier">request</span>.<span class="ruby-identifier">body</span>.<span class="ruby-identifier">to_s</span>
        <span class="ruby-keyword kw">end</span>
        
        <span class="ruby-identifier">request</span>.<span class="ruby-identifier">headers</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">key</span>, <span class="ruby-identifier">value</span><span class="ruby-operator">|</span>
          <span class="ruby-identifier">req</span>[<span class="ruby-identifier">key</span>] = <span class="ruby-identifier">value</span>
        <span class="ruby-keyword kw">end</span>
        
        <span class="ruby-identifier">request</span>.<span class="ruby-identifier">calculate_length!</span>
        
        <span class="ruby-identifier">res</span> = <span class="ruby-identifier">http</span>.<span class="ruby-identifier">request</span>(<span class="ruby-identifier">req</span>)
        
        <span class="ruby-identifier">response</span> = <span class="ruby-constant">Response</span>.<span class="ruby-identifier">new</span>
        <span class="ruby-identifier">response</span>.<span class="ruby-identifier">body</span> = <span class="ruby-identifier">res</span>.<span class="ruby-identifier">body</span>
        <span class="ruby-identifier">response</span>.<span class="ruby-identifier">headers</span> = <span class="ruby-constant">Hash</span>.<span class="ruby-identifier">new</span>
        <span class="ruby-identifier">res</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">key</span>, <span class="ruby-identifier">value</span><span class="ruby-operator">|</span>
          <span class="ruby-identifier">response</span>.<span class="ruby-identifier">headers</span>[<span class="ruby-identifier">key</span>] = <span class="ruby-identifier">value</span>
        <span class="ruby-keyword kw">end</span>
        <span class="ruby-identifier">response</span>.<span class="ruby-identifier">status_code</span> = <span class="ruby-identifier">res</span>.<span class="ruby-identifier">code</span>.<span class="ruby-identifier">to_i</span>
        <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">response</span>
      <span class="ruby-keyword kw">end</span></pre>
</body>
</html>